<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>V1.1.2</title>
    <!-- 引入 WeUI CDN 链接 -->
    <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/2.3.0/weui.min.css"/>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<!--切换样式-->
<style type="text/css">
    .weui-form-preview__hd .weui-form-preview__value {
        font-size: 14px;
    }

    .weui-navbar__item.weui-bar__item_on {
        color: #979095;
        background-color: #ccddef;
        cursor: pointer;
        font-family: Arial;
        font-weight: 600;
        font-size: 18px;
    }

    .small_font_gray {
        font-size: 10px;
        color: gray;

    }

    .new_top {
        color: red;
        cursor: pointer;
        font-family: Arial;
        font-weight: 500;
        font-size: 18px;
    }

    .new_top_title {
        color: red;
        font-family: Arial;
        font-weight: 600;
        font-size: 16px;
    }

    .new_top_font {
        color: red;
        font-family: Arial;
        font-size: 12px;
    }

    .weui-badge {
        color: #424242;
        background-color: #ccddef;
    }
</style>
<!-- loading toast -->
<div role="alert" id="loadingToast" style="display: none;">
    <div class="weui-mask_transparent"></div>
    <div class="weui-toast">
            <span class="weui-primary-loading weui-icon_toast">
              <span class="weui-primary-loading__dot"></span>
            </span>
        <p class="weui-toast__content">加载中</p>
    </div>
</div>

<div role="link" class="weui-media-box weui-media-box_text" id="newsTemplate" style="display:none">
    <a href="{href}">
        <strong aria-hidden="true" class="weui-media-box__title">{title}</strong>
        <!--<p class="weui-media-box__desc" aria-hidden="true" >{desc}</p>-->
        <ul class="weui-media-box__info" aria-hidden="true">
            <li class="weui-media-box__info__meta" aria-hidden="true">国家数据统计局</li>
            <li class="weui-media-box__info__meta" aria-hidden="true">{dateFormat}</li>
        </ul>
    </a>
</div>

<div class="weui-form-preview" id="myTemplate" style="display:none">
    <a href="./stock.html?code={stockcode}">
        <div role="option" class="weui-form-preview__hd">
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">{name}</label>
                <em class="weui-form-preview__value">{code}</em>
            </div>
            <div role="option" aria-labelledby="p1 js_a11y_comma p2 js_a11y_comma p3" class="weui-form-preview__bd">

                <div id="p12" class="weui-form-preview__item">
                    <label class="weui-form-preview__label">价格</label>
                    <span class="weui-form-preview__value">{price}<span class="weui-badge">{chgP}</span></span>
                </div>
                <div id="p102" class="weui-form-preview__item">
                    <label class="weui-form-preview__label">指标</label>
                    <span class="weui-form-preview__value">RSI:{rsi},rsi对比:{rsiDiff},MA:{ma}</span>
                </div>
            </div>
        </div>
    </a>
</div>

<div class="weui-form-preview" id="template" style="display:none">
    <a onclick="openUrl('./stock_minute.html?code={stockcode}')">
        <div role="option" class="weui-form-preview__hd">
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">{name}
                    <span class="weui-badge">{cuteLv}{autoCuteP}</span>
                    <span class="weui-badge">止盈止损:{autoCutePrice}</span>
                <em class="weui-form-preview__value">{code}</em>
            </div>
        </div>
        <div role="option" aria-labelledby="p1 js_a11y_comma p2 js_a11y_comma p3" class="weui-form-preview__bd">
            <!--
            <div id="p11" class="weui-form-preview__item">
                <label class="weui-form-preview__label">行业PE对比</label>
                <span class="weui-form-preview__value">当前:{peToday},行业:{pe1yTTM}</span>
            </div>
            -->
            <div id="p10" class="weui-form-preview__item">
                <label class="weui-form-preview__label">持仓<span class="weui-badge">rsi:{rsi}</span></label>
                <span class="weui-form-preview__value">{onHandMoney}万<span class="weui-badge">占比{onHandP}%</span></span>
            </div>
            <div id="p1" class="weui-form-preview__item">
                <label class="weui-form-preview__label">当前<span class="weui-badge">{chgP}</span></label>
                <span class="weui-form-preview__value">{price}</span>

            </div>
            <div class="weui-form-preview__item">
                {desc}
            </div>
            <div class="weui-form-preview__item">
                {buyRangeDesc}

            </div>
        </div>
    </a>
</div>

<div class="page">

    <div class="page__bd">
        <div class="weui-tab">
            <div class="weui-navbar">
                <div role="tab" aria-selected="true" aria-controls="panel1" id="tab1"
                     class="weui-navbar__item weui-bar__item_on">
                    策略
                </div>

                <div role="tab" aria-controls="panel2" id="tab2" class="weui-navbar__item">
                    今日
                </div>
                <!--
                <div role="tab" aria-controls="panel3" id="tab3" class="weui-navbar__item">
                    本周
                </div>
                <div role="tab" aria-controls="panel4" id="tab4" class="weui-navbar__item">
                    新闻<span class="weui-badge" style="background-color: gold;display:none;"
                              id="newsCount">今日有更新</span>
                </div>
                -->
            </div>
            <div role="tabpanel" id="panel1" aria-labelledby="tab1" class="weui-tab__panel">
                <div class="weui-form-preview">
                    <div role="option" class="weui-form-preview__hd">
                        <div class="weui-form-preview__item">
                            <label class="weui-form-preview__label">建议持仓比例</span></label>
                            <em class="weui-form-preview__value">
                                <span class="weui-badge" id="expect_onhand_p">Loading</span>
                                <span class="weui-badge" id="expect_onhand_money">Loading</span>
                            </em>
                        </div>
                    </div>
                    <div role="option" class="weui-form-preview__hd">
                        <div class="weui-form-preview__item">
                            <label class="weui-form-preview__label">长线指标<span class="small_font_gray">(80%以下购入100%谨慎)</span></label>
                            <em class="weui-form-preview__value"><span class="weui-badge" id="bft"></span></em>
                        </div>
                    </div>
                    <!--
                    <div role="option" class="weui-form-preview__hd">
                        <div class="weui-form-preview__item">
                            <label class="weui-form-preview__label">300风险溢价<span class="small_font_gray">(5.5以上买,6加倍买,3以下考虑卖)</span></label>
                            <em class="weui-form-preview__value"><span class="weui-badge" id="sz_rp"></span></em>
                        </div>
                    </div>
                    -->
                    <!--
                    <div role="option" class="weui-form-preview__hd">
                        <div class="weui-form-preview__item">
                            <label class="weui-form-preview__label">当前市场热度<span class="small_font_gray">(短线指标2~100分)</span></label>
                            <em class="weui-form-preview__value"><span class="weui-badge"
                                                                       id="sz_hot">Loading</span></em>
                        </div>
                    </div>
                    -->
                </div>

                <div class="weui-form-preview" id="view">
                    <div role="option" class="weui-form-preview__hd">
                        <div class="weui-form-preview__item">
                            <label class="weui-form-preview__label">上证指数
                            </label>
                            <em class="weui-form-preview__value" id="sz">Loading</em>
                            <span class="weui-badge" id="sz_chgp"></span>

                        </div>
                    </div>
                </div>
            </div>
            <div style="display: none;" role="tabpanel" id="panel2" aria-labelledby="tab3" class="weui-tab__panel">
                <div class="weui-panel__bd" id="today">

                </div>
            </div>
            <div style="display: none;" role="tabpanel" id="panel3" aria-labelledby="tab3" class="weui-tab__panel">
                <div class="weui-panel__bd" id="week">

                </div>
            </div>

            <div style="display: none;" role="tabpanel" id="panel4" aria-labelledby="tab3" class="weui-tab__panel">
                <div class="weui-panel__bd" id="news">
                    <div role="link" class="weui-media-box weui-media-box_text new_top">
                        <a href="http://www.gov.cn/shuju/chaxun/index.htm">
                            <strong aria-hidden="true"
                                    class="weui-media-box__title new_top_title">中国经济数据汇总(置顶)</strong>
                            <!--<p class="weui-media-box__desc" aria-hidden="true" >{desc}</p>-->
                            <ul class="weui-media-box__info new_top_font" aria-hidden="true">
                                <li class="weui-media-box__info__meta" aria-hidden="true">中国政府网</li>
                                <li class="weui-media-box__info__meta" aria-hidden="true">经济数据汇总</li>
                            </ul>
                        </a>
                    </div>
                    <div role="link" class="weui-media-box weui-media-box_text new_top">
                        <a href="http://www.gov.cn/zhengce/zuixin.htm">
                            <strong aria-hidden="true"
                                    class="weui-media-box__title new_top_title">中国最新政策(置顶)</strong>
                            <!--<p class="weui-media-box__desc" aria-hidden="true" >{desc}</p>-->
                            <ul class="weui-media-box__info new_top_font" aria-hidden="true">
                                <li class="weui-media-box__info__meta" aria-hidden="true">中国政府网</li>
                                <li class="weui-media-box__info__meta" aria-hidden="true">经济数据汇总</li>
                            </ul>
                        </a>
                    </div>
                </div>
            </div>

        </div>


    </div>
</div>
</body>
<script>
    function openUrl(url) {
        window.open(url, '_blank'); // '_blank' 会在新窗口或新标签页中打开URL
    }
    //获取url中的参数
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r != null) return unescape(r[2]);
        return null; //返回参数值
    }

    function loadData() {
        var loadUrl="/stock/onHandForCode";
        var code=getUrlParam("code");
        if(code !=null){
            loadUrl=loadUrl+"/"+code;
        }else{
            loadUrl="/stock/onHand";
        }
        $.ajax({url:loadUrl,success:function(result){
                $("#expect_onhand_p").html(result.todayView.expectOnHandP+"%");
                $("#expect_onhand_money").html(result.todayView.expctOnHandMoney+"万");
                $("#bft").html("巴菲特指数:"+result.todayView.btf+"%");
                $("#sz").html(result.todayView.sz.close);
                $("#sz_chgp").html(result.todayView.sz.chgp+"%");

                $(result.onHandDetailViewList).each(function (i, b) {
                    loadSuccess("买:", b);
                });
                 $("#loadingToast").hide();
            }});
    }

    function loadSuccess(event, buy) {
        var stock=buy.stockData;
        var t = $("#template").clone();
        $("#view").append(t);
        t.show();
        var buyDesc="";
        if(stock.isBuy==1){
            buyDesc="【买买买】";
        }
        if(stock.isSell==1){
            buyDesc="【卖卖卖】";
        }
        t.html(t.html()
            .replace("{name}", stock.stockName+buyDesc)
            .replace("{code}", stock.stockCode)
            .replace("{stockcode}", stock.stockCode)
            .replace("{price}", stock.money)
            .replace("{autoCutePrice}", stock.autoCutePrice)
            .replace("{cuteLv}", buy.desc)
            .replace("{onHandMoney}", buy.onHandMoney)
            .replace("{onHandP}", buy.onHandP)
            .replace("{maDiff}", "")
            .replace("{curdate}", stock.curDate)
            .replace("{count}", "")
            .replace("{pe1yTTM}", "")
            .replace("{peToday}", "")
            .replace("{autoCuteP}", buy.autoCuteP + "%")
            .replace("{chgP}", stock.chgp + "%")
            .replace("{rsi}", stock.rsi1)
            .replace("{desc}", stock.desc)
            .replace("{buyRangeDesc}", stock.buyRangeDesc)
        );

        if(stock.isBuy==1 ||stock.isSell==1){
            $("#today").append(t.clone());
        }
    }



    function initTab() {
        $('.weui-navbar__item').on('click', function () {
            $(this).attr('aria-selected', 'true').addClass('weui-bar__item_on');
            $(this).siblings('.weui-bar__item_on').removeClass('weui-bar__item_on').attr('aria-selected', 'false');
            var panelId = '#' + $(this).attr('aria-controls');
            $(panelId).css('display', 'block');
            $(panelId).siblings('.weui-tab__panel').css('display', 'none');
        });
    }

    $(function () {
        initTab();
        $('#loadingToast').fadeIn(100);
        loadData();

    });
</script>
</html>